package exam;

import java.util.*;

public class Exec03 {

    public static void main(String[] args) {
        // 插入数据
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要插入的位置");
        int index = sc.nextInt();
        System.out.println("请输入要插入的数字");
        int key = sc.nextInt();
        int[] nums = {-9, -1, 2, 3, 3, 4, 10};
        int[] newArr = new int[nums.length + 1];
        insertData(nums, newArr, index, key);
        System.out.println(Arrays.toString(newArr));
    }

    public static void insertData(int[] arr, int[] newArr, int index, int key) {
        System.arraycopy(arr, 0, newArr, 0, index);
        newArr[index] = key;
        System.arraycopy(arr, index, newArr, index + 1, arr.length - index);

    }
}
